trivial-httpd: Fix leak of option context
authorColin Walters <walters@verbum.org>
Sun, 24 Jul 2016 18:54:07 +0000 (14:54 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 28 Jul 2016 10:10:17 +0000 (10:10 +0000)
Right now our valgrind runs also end up valgrinding the
`trivial-httpd` code, so while it doesn't matter, let's fix this leak
anyways.  We need to avoid calling `_exit()` since that won't run the
cleanup functions.

Closes: #410
Approved by: giuseppe

src/ostree/ot-builtin-trivial-httpd.c

index 5b942cd5108c74d4f582def9cadefdf165f38c6c..30c593c20c8b5327e951c92de157ec47bb55e51e 100644 (file)
@@ -386,7 +386,7 @@ gboolean
 ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
-  GOptionContext *context;
+  g_autoptr(GOptionContext) context = NULL;
   const char *dirpath;
   OtTrivialHttpd appstruct = { 0, };
   OtTrivialHttpd *app = &appstruct;
@@ -501,8 +501,8 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable,
         }
       else if (pid > 0)
         {
-          /* Parent */
-          _exit (0);
+          ret = TRUE;
+          goto out;
         }
       /* Child, continue */
       /* Daemonising: close stdout/stderr so $() et al work on us */
@@ -559,7 +559,5 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable,
  out:
   g_clear_object (&app->root);
   g_clear_object (&app->log);
-  if (context)
-    g_option_context_free (context);
   return ret;
 }